<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="时间">
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="totals"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="gotpage"
    >
    </el-pagination>
  </div>
</template>

<style>
.el-table .warning-row {
  background: pink;
}

.el-table .success-row {
  background: deepskyblue;
}
</style>

<script>
// //局部使用axios
// import axios from "axios";

export default {
  data() {
    return {
      totals: 0,
      pageSize: 5,
      currentPage: 1,
      tableData: []
    }
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    getDate() {
      let parpem = {"currentPage": this.currentPage, "pageSize": this.pageSize}
      //  使用axios发送请求到后端
      this.$http.post("/user/list", parpem)
        .then(res => {
          this.tableData = res.data.data
          this.totals = res.data.totals
        })
        .catch(res => {
          alert("请求失败")
        })
    }, gotpage(ys) {
      this.currentPage =ys
      console.log(ys)
      this.getDate()
    }
  },
//  钩子函数
  mounted() {
    this.getDate()
  }
}
</script>



